package com.ruoyi.web.controller.basicInfo;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.basicInfo.domain.Ship;
import com.ruoyi.basicInfo.service.IShipService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 船舶信息Controller
 * 
 * @author zbw
 * @date 2022-07-16
 */
@RestController
@RequestMapping("/basicInfo/ship")
public class ShipController extends BaseController
{
    @Autowired
    private IShipService shipService;

    /**
     * 查询船舶信息列表
     */
    @PreAuthorize("@ss.hasPermi('basicInfo:ship:list')")
    @GetMapping("/list")
    public TableDataInfo list(Ship ship)
    {
        startPage();
        List<Ship> list = shipService.selectShipList(ship);
        return getDataTable(list);
    }

    /**
     * 导出船舶信息列表
     */
    @PreAuthorize("@ss.hasPermi('basicInfo:ship:export')")
    @Log(title = "船舶信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Ship ship)
    {
        List<Ship> list = shipService.selectShipList(ship);
        ExcelUtil<Ship> util = new ExcelUtil<Ship>(Ship.class);
        util.exportExcel(response, list, "船舶信息数据");
    }

    /**
     * 获取船舶信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('basicInfo:ship:query')")
    @GetMapping(value = "/{shipId}")
    public AjaxResult getInfo(@PathVariable("shipId") String shipId)
    {
        return AjaxResult.success(shipService.selectShipByShipId(shipId));
    }

    /**
     * 新增船舶信息
     */
    @PreAuthorize("@ss.hasPermi('basicInfo:ship:add')")
    @Log(title = "船舶信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Ship ship)
    {
        return toAjax(shipService.insertShip(ship));
    }

    /**
     * 修改船舶信息
     */
    @PreAuthorize("@ss.hasPermi('basicInfo:ship:edit')")
    @Log(title = "船舶信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Ship ship)
    {
        return toAjax(shipService.updateShip(ship));
    }

    /**
     * 删除船舶信息
     */
    @PreAuthorize("@ss.hasPermi('basicInfo:ship:remove')")
    @Log(title = "船舶信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{shipIds}")
    public AjaxResult remove(@PathVariable String[] shipIds)
    {
        return toAjax(shipService.deleteShipByShipIds(shipIds));
    }
}
